
*** Replication Do-File for Figure 1 in BJPS Paper 'A New Dilemma of Social Democracy?' (19/09/23)

*** Pre-Clean Version

***********************************************************************************

version 14
clear all
set more off, perm
set scrollbufsize 300000
set maxvar 32767

cd "C:\Users\Zack.Grant\Dropbox (Nuffield College)\PROJECTS\IDENTITYPOL-GB\New Dilemma of Social Democracy Paper\Data" 

*** Download raw data from https://www.britishelectionstudy.com/data-objects/cross-sectional-data/ and save to cd.



******* PART 1: DOWNLOAD BES 1987 AND 2019 AND MERGE ******* 

use 87BES.dta, clear 
foreach var of varlist serialno - v126 {
        rename `var' bes87_`var'
}
gen bes_ID = _n  //* Max: 5999. 
save MERGE\BES_87, replace

use bes_rps_2019_ukds_1.3.0.dta, clear 
foreach var of varlist finalserialno - wt_vote_cses {
        rename `var' bes19_`var'
}
gen bes_ID = _n + 5999 
save MERGE\BES_19, replace


use MERGE\BES_19.dta, clear
merge 1:1 bes_ID using MERGE\BES_87.dta
drop _merge
save MERGE\BES_CombinedPostElections, replace

order bes_ID, before(bes19_finalserialno)


******* PART 2: RECODE AND CLEAN DATA ******* 


* Generate Survey Year Dummy

gen surveyyear =.
label variable surveyyear "Survey Year (BES)"
replace surveyyear = 1987 if bes87_serialno !=.
replace surveyyear = 2019 if bes19_finalserialno !=.


* Identify Proper Weight Variables

gen bes87_wtVOTE = bes87_weight if surveyyear == 1987
gen bes19_wtVOTE = bes19_wt_vote if surveyyear == 2019



* Code Vote Choice Variable (Simplified)

gen combovote =.
label define combovote 0 "Did Not Vote" 1 "Labour" 2 "Conservatives" 3 "Liberals/SDP" 4 "SNP" 5 "Plaid Cymru" 6 "BNP/NF" 7 "UKIP" 8 "Greens" 10 "Other", replace
label variable combovote "Respondent Vote Choice (Long)"
label values combovote combovote

gen bes87vote =. //* 1987
replace bes87vote = 1 if bes87_v8a == 2 //* Lab
replace bes87vote = 2 if bes87_v8a == 1 //* Con
replace bes87vote = 3 if bes87_v8a == 3 //* Lib-SDP
replace bes87vote = 4 if bes87_v8a == 6 //* SNP
replace bes87vote = 5 if bes87_v8a == 7 //* Plaid
replace bes87vote = 8 if bes87_v8a == 8 //* Greens
replace bes87vote = 0 if bes87_v6a   == 2  | inlist(bes87_turnout,0,7) 

gen bes19vote =. //* 2019
replace bes19vote = 1 if bes19_b02   == 1 //* Lab
replace bes19vote = 2 if bes19_b02   == 2 //* Con
replace bes19vote = 3 if bes19_b02   == 3 //* Lib-SDP
replace bes19vote = 4 if bes19_b02   == 4 //* SNP
replace bes19vote = 5 if bes19_b02   == 5 //* Plaid
replace bes19vote = 8 if bes19_b02   == 6 //* Greens
replace bes19vote = 7 if bes19_b02   == 7 | bes19_b02   == 8 //* UKIP / Brexit
replace bes19vote = 10 if bes19_b02 == 9  | bes19_b02 == 10  | bes19_b02 == 11 //* Other

replace bes19vote = 0 if bes19_b01 == 2 | bes19_b02 == 12 //* Non-Voter

label values bes87vote bes19vote combovote



* Code Occupational Class (Recode 1987 data so comparable to 2019)*

* Old Middle Class (1)         =  Employers, Managers, Administrators, Farmers, and Professionals Self-Employed, e.g. lawyers, doctors, psychologists, senior officers in police/fire/NHS etc.)
* New Middle Class (2)         =  Professional Employees + Higher Supervisors [e.g. office supervisors], e.g. web designers, nurses, teachers, social workers, academics, scientists, engineers, physios)
* Intermediate Class (3)       =  Intermediate Classes (Lower white collar employees, Clerks, Call centre workers, sales teams, junior admin staff - i.e. classic office workers - technicians, IT staff, police, firemen)
* Own Account (4)              =  Own Account (importerts and exporters, self employed tradespeople)
* Foreman (5)                  =  Foremen and Lower Supervisors
* Working Class (6)            =  Working Class (Routine and semi-routine employees without supervisory responsibilities, e.g. metal workers, shelf fillers, security workers, porters, waiters, cleaners, drivers, telephone salespeople, checkout workers, employed hairdressers, care workers, scaffolders, cooks, employed craftspeople, childcare workers)
* Others outside labour force (7) = e.g. students and long-term unemployed



gen bes87_occupclass =. //* 1987
label define bes87_occupclass 1 "Old Middle Class" 2 "New Middle Class" 3 "Intermediate Class" 4 "Own Account" 5 "Foremen + Supervisors" 6 "Working Class" 7 "Other Outside Labour Force", replace
label variable bes87_occupclass "Respondent Occupational Class"
label values bes87_occupclass bes87_occupclass

replace bes87_occupclass = 1 if inlist(bes87_v50a3 ,1,2,3,13)  //* OMC
replace bes87_occupclass = 2 if inlist(bes87_v50a3 ,4,5) //* NMC
replace bes87_occupclass = 3 if inlist(bes87_v50a3 ,6) //* JMC
replace bes87_occupclass = 4 if inlist(bes87_v50a3 ,12,14) //* Own Account
replace bes87_occupclass = 5 if inlist(bes87_v50a3 ,8) //* Foremen
replace bes87_occupclass = 6 if inlist(bes87_v50a3, 7,9,10,11,15) //* Working Class

replace bes87_occupclass = 1 if bes87_v50a3  == 16 & inrange(bes87_v50d,1,7000) //* Military with Management (OMC)
replace bes87_occupclass = 6 if bes87_v50a3  == 16 & bes87_v50d == 0 //* Military without Management (WC)
replace bes87_occupclass = 1 if bes87_v50a5 == 5 //* Self-employed with employees
replace bes87_occupclass = 1 if bes87_occupclass == 2 & bes87_v50a5 == 6 //* self-employed no employees
replace bes87_occupclass = 4 if inrange(bes87_occupclass,4,7) & bes87_v50a5 == 6 //* self-employed no employees
replace bes87_occupclass = 5 if bes87_occupclass ==. & bes87_v50a5 == 8 //* Supervisors
replace bes87_occupclass = 5 if inrange(bes87_occupclass,4,7) & bes87_v50a5 == 8 //* Supervisors

* By Husband if Own Class NA
replace bes87_occupclass = 1 if bes87_occupclass ==. &  inlist(bes87_v52a3 ,1,2,3,13)  //* OMC
replace bes87_occupclass = 2 if bes87_occupclass ==. &  inlist(bes87_v52a3 ,4,5) //* NMC
replace bes87_occupclass = 3 if bes87_occupclass ==. &  inlist(bes87_v52a3 ,6) //* JMC
replace bes87_occupclass = 4 if bes87_occupclass ==. &  inlist(bes87_v52a3 ,12,14) //* Own Account
replace bes87_occupclass = 5 if bes87_occupclass ==. &  inlist(bes87_v52a3 ,8) //* Foremen
replace bes87_occupclass = 6 if bes87_occupclass ==. &  inlist(bes87_v52a3 ,7,9,10,11,15) //* Working Class

replace bes87_occupclass = 1 if bes87_occupclass ==. &  bes87_v52a3  == 16 & inrange(bes87_v52d,1,9998) //* Military with Management (OMC)
replace bes87_occupclass = 6 if bes87_occupclass ==. &  bes87_v52a3  == 16 & bes87_v52d == 0 //* Military without Management (WC)

replace bes87_occupclass = 1 if bes87_occupclass ==. & bes87_v52a5  == 5 //* Self-employed with employees
replace bes87_occupclass = 4 if bes87_occupclass ==. &  bes87_v52a5  == 6 //* self-employed no employees
replace bes87_occupclass = 5 if bes87_occupclass ==. & bes87_v52a5  == 8 //* Supervisors


* By Father if Own Class NA
replace bes87_occupclass = 1 if bes87_occupclass ==. &   inlist(bes87_v47a3 ,1,2,3,13)  //* OMC
replace bes87_occupclass = 2 if bes87_occupclass ==. &   inlist(bes87_v47a3 ,4,5) //* NMC
replace bes87_occupclass = 3 if bes87_occupclass ==. &   inlist(bes87_v47a3 ,6) //* JMC
replace bes87_occupclass = 4 if bes87_occupclass ==. &   inlist(bes87_v47a3 ,12,14) //* Own Account
replace bes87_occupclass = 5 if bes87_occupclass ==. &   inlist(bes87_v47a3 ,8) //* Foremen
replace bes87_occupclass = 6 if bes87_occupclass ==. &   inlist(bes87_v47a3, 7,9,10,11,15) //* Working Class

replace bes87_occupclass = 1 if bes87_occupclass ==. &   bes87_v47a3  == 16 & inrange(bes87_v47d,1,7000) //* Military with Management (OMC)
replace bes87_occupclass = 6 if bes87_occupclass ==. &   bes87_v47a3  == 16 & bes87_v47d == 0 //* Military without Management (WC)

replace bes87_occupclass = 1 if bes87_occupclass ==. & bes87_v47a5  == 5 //* Self-employed with employees
replace bes87_occupclass = 4 if bes87_occupclass ==. & bes87_v47a5 == 6 //* self-employed no employees
replace bes87_occupclass = 5 if bes87_occupclass ==. & bes87_v47a5  == 8 //* Supervisors

replace bes87_occupclass = 7 if bes87_occupclass ==. & inlist(bes87_v49a,1,2,5,6,7,8,9,10) //* Remaining unemployed go to NA




gen bes19_occupclass =.  //* 2019
label define bes19_occupclass 1 "Old Middle Class" 2 "New Middle Class" 3 "Intermediate Class" 4 "Own Account" 5 "Foremen + Supervisors" 6 "Working Class" 7 "Other Outside Labour Force", replace
label variable bes19_occupclass "Respondent Occupational Class"
label values bes19_occupclass bes19_occupclass

replace bes19_occupclass = 1 if inlist( bes19_ns_sec,1,2,3.3,3.4,4.3,5,8.1,8.2,9.2)  //* OMC
replace bes19_occupclass = 2 if inlist( bes19_ns_sec,3.1,3.2,4.1,4.2,6) //* NMC
replace bes19_occupclass = 3 if inlist( bes19_ns_sec,7.1,7.2,7.3,7.4) //* JMC
replace bes19_occupclass = 4 if inlist( bes19_ns_sec,4.4,9.1) //* Own Account
replace bes19_occupclass = 5 if inlist( bes19_ns_sec,10) //* Foremen
replace bes19_occupclass = 6 if inrange( bes19_ns_sec,11.1,13.5) //* Working Class

replace bes19_occupclass = 1 if bes19_y24 == 2 //* Employers to top category
replace bes19_occupclass = 4 if bes19_y24 == 1  & bes19_occupclass != 1 & bes19_occupclass != 2 //* Self-employed non-profs to correct category
replace bes19_occupclass = 7 if bes19_occupclass ==. & inlist(bes19_y17,5,6,7,8,9,10,11) //* Assign others to out of Labour force
replace bes19_occupclass = 7 if bes19_occupclass ==. & bes19_ns_sec == 14.1



* Code Educational Attainment

gen educgrp =.
label define educgrp  1 "Minimum School Leave / Below GCSE /No Qual" 2 "More than Minimum School Leaving Age / Some Qual" 3 "Post-16 A-Level or Equivalent" 4 "Degree" , replace
label variable educgrp "Education (4 Groups)"
label values educgrp educgrp


* 1987
replace educgrp = 4 if  bes87_v56r == 92 | bes87_v56l == 12 | bes87_v56m == 13 | bes87_v56o == 15 
replace educgrp = 3 if  educgrp ==. & bes87_v56k == 11 | educgrp ==. & bes87_v56n == 14 | educgrp ==. &  bes87_v56k == 11 | educgrp ==. &  bes87_v56d == 3 | educgrp ==. & bes87_v56j == 10
replace educgrp = 2 if  educgrp ==. & bes87_v56a != 0 & bes87_v55 !=. 
replace educgrp = 1 if  bes87_v56a == 0 

* 2019
replace educgrp = 1 if inlist(bes19_edlevel,0,1)
replace educgrp = 2 if educgrp ==. & inlist(bes19_edlevel,2) | educgrp ==. & bes19_education == 18 
replace educgrp = 3 if educgrp ==. & inlist(bes19_edlevel,3) | educgrp ==. & bes19_education == 6
replace educgrp = 4 if educgrp ==. & inlist(bes19_edlevel,4,5) 


gen degree =. //* Dummy for if University Degree or Not
label var degree "R has a degree or equivalent"
replace degree = 1 if educgrp == 4
replace degree = 0 if inrange(educgrp,1,3)

gen bes87_degree = degree if surveyyear == 1987
gen bes19_degree = degree if surveyyear == 2019


 * Code Ethnicity as White v Non-White /Mixed
 
* 1987 
gen bes87_ethnicity =.
label var bes87_ethnicity "White Respondent v Other"
label define ethnicity 1 "White" 0 "Non-White / Mixed", replace
label values bes87_ethnicity ethnicity

replace bes87_ethnicity = 1 if surveyyear == 1987 & bes87_v58a  == 1
replace bes87_ethnicity = 0 if surveyyear == 1987 & inrange(bes87_v58a ,2,4)


* 2019
gen bes19_ethnicity =.
label var bes19_ethnicity "White Respondent v Other"
label define ethnicity 1 "White" 0 "Non-White / Mixed", replace
label values bes19_ethnicity ethnicity

replace bes19_ethnicity = 1 if inlist(bes19_y11,1,2,3,4)
replace bes19_ethnicity = 0 if inlist(bes19_y11,5,6,7,8,9,10,11,12,13,14,15,16,17,18)

  
  
  
** Use Occupation, Education, and Race Data to Create 4 Main Class-Race Groups for Main Paper ** 
  
  * 1987
gen ClassGroup_1987 =.
label define ClassGroup_1987 1 "White Working Class" 2 "White Graduates" 3 "Other Whites" 4 "Ethnic Minorities", replace
label values ClassGroup_1987 ClassGroup_1987

replace ClassGroup_1987 = 1 if bes87_occupclass == 6 & bes87_ethnicity == 1 & degree == 0
replace ClassGroup_1987 = 2 if bes87_occupclass != . & bes87_ethnicity == 1 & degree == 1
replace ClassGroup_1987 = 3 if ClassGroup_1987 ==. & bes87_ethnicity == 1 & bes87_occupclass != . & degree !=. 
replace ClassGroup_1987 = 4 if ClassGroup_1987 ==. & bes87_ethnicity == 0 & bes87_occupclass != . & degree !=. 

   * 2019
  
gen ClassGroup_2019 =.
label define ClassGroup_2019 1 "White Working Class" 2 "White Graduates" 3 "Other Whites" 4 "Ethnic Minorities", replace
label values ClassGroup_2019 ClassGroup_2019

replace ClassGroup_2019 = 1 if bes19_occupclass == 6 & bes19_ethnicity == 1 & degree == 0
replace ClassGroup_2019 = 2 if bes19_occupclass != . & bes19_ethnicity == 1 & degree == 1
replace ClassGroup_2019 = 3 if ClassGroup_2019 ==. & bes19_ethnicity == 1 & bes19_occupclass != . & degree !=. 
replace ClassGroup_2019 = 4 if ClassGroup_2019 ==. & bes19_ethnicity == 0 & bes19_occupclass != . & degree !=. 

    

********************************	
	
label var bes_ID "BES Respondent ID Number" 
label var surveyyear "BES Survey Year Dummy" 
label var bes87_wtVOTE "BES 1987 Weight" 
label var bes19_wtVOTE "BES 2019 Weight" 
label var bes87vote "BES 1987 Vote Choice" 
label var bes19vote "BES 2019 Vote Choice" 
label var ClassGroup_1987 "Class-Race Groups in BES 1987" 
label var ClassGroup_2019 "Class-Race Groups in BES 2019"
label var bes87_ethnicity "Race in BES 1987" 
label var bes19_ethnicity "Race in BES 2019" 
label var bes87_occupclass "Occupation in BES 1987" 
label var bes19_occupclass "Occupation in BES 2019" 
label var bes87_degree "Uni Degree Dummy in BES 1987" 
label var bes19_degree "Uni Degree Dummy in BES 2019" 
	
	
keep bes_ID surveyyear bes87_wtVOTE bes19_wtVOTE bes87vote bes19vote ClassGroup_1987 ClassGroup_2019 bes87_ethnicity bes19_ethnicity bes87_occupclass bes19_occupclass bes87_degree bes19_degree
	
	
**** FIGURE 1 STATISTICS* ('Different Class-Ethnicity Groups as a Percentage of the Electorate and Labour Vote')
	
	
*** Size of Class Groups in British Electorate (1987)
 
 svyset [pweight= bes87_wtVOTE], psu(bes_ID)
 svy: tab ClassGroup_1987  if bes87_occupclass  != 7 //* (Exclude 0.6% of sample whose class was NA, results similar if include)
	
*** Size of Class Groups in Labour Electorate (1987)
	
 svy: tab bes87vote ClassGroup_1987 if bes87_occupclass  != 7, row 
  
  
  
  
*** Size of Class Groups in British Electorate (2019)
	
 svyset [pweight= bes19_wtVOTE], psu(bes_ID)
 svy: tab ClassGroup_2019	if bes19_occupclass  != 7  //* (Exclude 5.9% of sample whose class was NA, results similar if include)
	
*** Size of Class Groups in British Electorate (2019)
	
 svyset [pweight= bes19_wtVOTE], psu(bes_ID)
 svy: tab bes19vote ClassGroup_2019  if bes19_occupclass != 7, row 
  
	

* Note: Figure itself made in Excel
	
	
